/***********************************************
 This file is part of redia-library-app-ios.
 
 Copyright (c) 2012, 2013 Redia A/S
 
 Redia-library-app-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-library-app-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-library-app-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */


#import <Foundation/Foundation.h>
#import "XMLRPCConnectionDelegate.h"
#import "InfoGalleriXmlRpcClient201009.h"
#import "InfoObject.h"
#import "ChannelFetchCompleteDelegate.h"
#import "InfoGalleriPlistPackageFetcher.h"
#import "InfoObjectFetchCompleteDelegate.h"

@interface InfoGalleriXmlRpcClient201009ChannelFetchDelegate : NSObject <XMLRPCConnectionDelegate, UIAlertViewDelegate, PackageFetchComplete, ProgressDisplayDelegate> {
	InfoGalleriXmlRpcClient201009* client;
	NSMutableArray* infoObjects;
	
	id<ChannelFetchCompleteDelegate> channelFetchCompleteDelegate;
	
	//NSString* elementCachePath;
	
	
	int pendingChannelCounter;
    int totalChannelNum;
    NSMutableArray* pendingChannelIDs;

    NSMutableArray* cachedElements;
    
    bool usingNewBackend;
    InfoGalleriPlistPackageFetcher* packageFetcher;
}

@property (nonatomic, strong) NSMutableArray* infoObjects;
@property (nonatomic) BOOL fetchChannelsSequentially;
@property (nonatomic, weak) id<InfoObjectFetchCompleteDelegate> infoObjectFetchCompleteDelegate;

- (id)init;

- (void)useNewRediaPublishClient;
- (bool)isUsingNewBackend;

- (void)fetchGalleryForCustomer:(NSString*)customer withGallery:(NSString*)gallery delegate:(id<ChannelFetchCompleteDelegate>)delegate;

- (void)fetchFromCacheWithDelegate:(id<ChannelFetchCompleteDelegate>)delegate;

- (void)fetchFromPackageForCustomer:(NSString*)customer withGallery:(NSString*)gallery delegate:(id<ChannelFetchCompleteDelegate>)delegate;

- (void)fetchSingleInfoObjectForCustomer:(NSString*)customer objectId:(NSString*)objectId delegate:(id<InfoObjectFetchCompleteDelegate>)delegate;

-(void)packageFetchComplete:(NSString *)filepath;
-(void)packageFetchError:(NSError *)error;
-(void)progress:(float)newprogress; //progress from package fetch

- (void)retreiveInfoObjectsForCustomer: (NSString*) customerID withGallery: (NSString*)gallery;
- (void)request: (XMLRPCRequest *)request didReceiveResponse: (XMLRPCResponse *)response;
- (void)request: (XMLRPCRequest *)request didFailWithError: (NSError *)error;
- (void)request: (XMLRPCRequest *)request didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
- (void)request: (XMLRPCRequest *)request didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;

- (void)generalNetworkFailure:(NSString*)description errrorcode:(int)code function:(const char*)func_name lineno:(int)line;

- (InfoGalleriXmlRpcClient201009*)getClient;

@end
